import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:matuo/route/RouteUtils.dart';
import 'package:matuo/utils/Logcat.dart';

import '../../generated/l10n.dart';
import '../../navigation/navigation_bar_widget.dart';
import '../../utils/DIYColors.dart';
import '../../utils/Utils.dart';
import 'DevicePage.dart';
import 'HealthPage.dart';
import 'MinePage.dart';
import 'MovementPage.dart';

class TobPage extends StatefulWidget {
  const TobPage({super.key});

  @override
  State<StatefulWidget> createState() {
    return new _TobPageState();
  }
}

class _TobPageState extends State<TobPage> with WidgetsBindingObserver {
  final List<Widget> tabItems = [];

  final List<String> tabLabels = [
    S.of(RouteUtils.context).Health,
    S.of(RouteUtils.context).Device,
    S.of(RouteUtils.context).Movement,
    S.of(RouteUtils.context).Mine
  ];
  final List<String> tabIcons = [
    Utils.instance.getImagePathPNG("icon_nav_health"),
    Utils.instance.getImagePathPNG("icon_nav_device"),
    Utils.instance.getImagePathPNG("icon_nav_exercise"),
    Utils.instance.getImagePathPNG("icon_nav_mine"),
  ];
  final List<String> tabActiveIcons = [
    Utils.instance.getImagePathPNG("icon_nav_health_checked"),
    Utils.instance.getImagePathPNG("icon_nav_device_checked"),
    Utils.instance.getImagePathPNG("icon_nav_exercise_checked"),
    Utils.instance.getImagePathPNG("icon_nav_mine_checked"),
  ];

  final List<Color> tabColors = [];

  @override
  void initState() {
    super.initState();
    // WidgetsBinding.instance.addObserver(this);

    initTabPage();
    // getCurrentLanguage();
  }

  @override
  void dispose() {
    // WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  // @override
  // void didChangeAppLifecycleState(AppLifecycleState state) {
  //   if (state == AppLifecycleState.resumed) {
  //     setState(() {
  //       getCurrentLanguage();
  //     });
  //   }
  // }

  void getCurrentLanguage() {
    // 获取当前系统语言
    String language = window.locale.languageCode;
    Logcat.instance.d("当前手机系统语言为：$language");
  }

  void initTabPage() {
    tabItems.add(const HealthPage());
    tabItems.add(const DevicePage());
    tabItems.add(const MovementPage());
    tabItems.add(const MinePage());
    tabColors.add(DIYColors.gray_f4);
    tabColors.add(DIYColors.gray_f4);
    tabColors.add(DIYColors.gray_f4);
    tabColors.add(DIYColors.gray_f4);
  }

  var tabLabel = S.of(RouteUtils.context).Health;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        extendBodyBehindAppBar: true,
        backgroundColor: Colors.transparent,
        appBar: null,
        body: NavigationBarWidget(
            tabColors: tabColors,
            tabItems: tabItems,
            tabLabels: tabLabels,
            tabIcons: tabIcons,
            tabActiveIcons: tabActiveIcons,
            onItemChange: (index) {
              tabLabel = tabLabels[index];
              Logcat.instance.d('当前选中的文字：${tabLabel}');
            }));
  }
}
